<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #result{
            width: 400px; height: 300px;border:solid 1px #ddd;
        }
    </style>
</head>
<body>
    <a href="#home">Home</a>
    <a href="#about">About</a>
    <hr>
    <div id="result">

    </div>

    <script>
        let result = document.querySelector("#result");
        //全局的时间  hashChange ,当 url 的 hash 值发生改变的时候, 触发该事件
        window.addEventListener("hashchange", function(){
            //获取当前网页 URL 中的锚点 『hash』
            // console.log(location);
            switch (location.hash) {
                case '#home':
                    result.innerHTML = '首页';
                    break;
                case '#about':
                    result.innerHTML = '关于我们';
                    break;
                default:
                    result.innerHTML = '<h1>404 Not Found</h1>';
                    break;
            }
        });
    </script>
</body>
</html>